[id].vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- Banner1 -->
  5. <HomeBanner1></HomeBanner1>
  6. <!-- 面包屑导航 -->
  7. <div class="breadcrumb">
  8. <div class="inner">
  9. <span class="location">当前位置:</span>
  10. <el-breadcrumb :separator-icon="ArrowRight">
  11. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  12. <el-breadcrumb-item :to="{ path: `/primaryNavigation/${listid}` }"
  13. v-show="name">{{ name }}</el-breadcrumb-item>
  14. <el-breadcrumb-item>{{ newsDetail.con_title }}</el-breadcrumb-item>
  15. </el-breadcrumb>
  16. </div>
  17. </div>
  18. <!-- 资讯列表 -->
  19. <div class="newsDetail">
  20. <div class="inner">
  21. <div class="innerLeft">
  22. <!-- <div class="LeftTop">
  23. <h1>{{ newsDetail.list_title }}</h1>
  24. </div> -->
  25. <div class="leftBottomTitle">{{ newsDetail.con_title }}</div>
  26. <div class="leftBottom" v-html="newsDetail.content"></div>
  27. </div>
  28. <div class="innerRight">
  29. <div class="rightMenuTitle">导航列表</div>
  30. <ul>
  31. <li v-for="(item, index) in bottomMenu" :key="index">
  32. <NuxtLink :to="`/speciaArticle/${item.id}`" target="_blank" v-if="item.id == pageId && item.id != 7"
  33. class="active">{{ item.name }}</NuxtLink>
  34. <NuxtLink :to="`/speciaArticle/${item.id}`" target="_blank"
  35. v-else-if="item.id != pageId && item.id != 7">{{ item.name }}</NuxtLink>
  36. <NuxtLink :to="`/specialList/${item.id}`" target="_blank"
  37. v-if="item.id == 7 && pageId == 7 && routeHref == '/specialList/7'" class="active">{{ item.name }}
  38. </NuxtLink>
  39. <NuxtLink :to="`/specialList/${item.id}`" target="_blank" v-else-if="item.id == 7">{{ item.name }}
  40. </NuxtLink>
  41. </li>
  42. </ul>
  43. </div>
  44. <div style="clear: both;"></div>
  45. </div>
  46. </div>
  47. <!-- 页面底部 -->
  48. <HomeFoot></HomeFoot>
  49. </template>
  50. <script setup>
  51. import { onMounted } from 'vue'
  52. import { ElBreadcrumb, ElBreadcrumbItem } from 'element-plus'
  53. import { ArrowRight } from '@element-plus/icons-vue'
  54. const nuxtApp = useNuxtApp();
  55. const axios = nuxtApp.$axios;
  56. //获得跳转过来的id
  57. const route = useRoute();
  58. const articleId = route.params.id; //获得该页面的id
  59. const listid = route.query.listId; //获得该页面的id
  60. const name = route.query.listName; //获得该页面的id
  61. const pageId = route.params.id; //获得该页面的id
  62. const routeHref = route.href;
  63. console.log(333333)
  64. console.log(route.href)
  65. const newsDetail = ref({})
  66. console.log(articleId)
  67. const routeNewsTtitle = ref("");
  68. // 定义响应式数据
  69. const seoData = ref({
  70. title: '三农资讯网',
  71. description: '默认描述',
  72. keywords: '默认关键词',
  73. image: 'https://example.com/default-image.jpg'
  74. });
  75. // 在 onMounted 钩子中获取数据
  76. onMounted(async () => {
  77. try {
  78. const response = await axios.get(`/web/getWebsiteCategoryHead?catid=${articleId}`);
  79. const data = response.data.website_head; // 假设接口返回的数据在 data 字段中
  80. console.log(seoData.value.title)
  81. // 更新 seoData
  82. seoData.value = {
  83. title: data.seo_title,
  84. description: data.seo_description,
  85. keywords: data.seo_keywords,
  86. image: data.seo_image
  87. };
  88. console.log(seoData.value.title)
  89. } catch (error) {
  90. console.error('获取 SEO 数据失败:', error);
  91. // 设置默认值
  92. seoData.value = {
  93. title: '三农资讯网',
  94. description: '默认描述',
  95. keywords: '默认关键词',
  96. image: 'https://example.com/default-image.jpg'
  97. };
  98. }
  99. });
  100. // 监听 seoData 的变化,动态设置 SEO 字段
  101. watch(seoData, (newVal) => {
  102. if (newVal.title) { // 确保 title 有值
  103. useSeoMeta({
  104. title: newVal.title, // 使用动态值
  105. description: newVal.description,
  106. ogTitle: newVal.title,
  107. ogDescription: newVal.description,
  108. ogImage: newVal.image,
  109. twitterTitle: newVal.title,
  110. twitterDescription: newVal.description,
  111. twitterImage: newVal.image,
  112. keywords: newVal.keywords
  113. });
  114. }
  115. }, { immediate: true });
  116. //获取详情
  117. const getNewsInfo = async () => {
  118. const response = await axios.get(`/web/getWebsiteFooterCategoryInfo?fcat_id=${articleId}`);
  119. newsDetail.value = response.data;
  120. console.log(newsDetail.value.title)
  121. if (newsDetail.value.title.length > 30) {
  122. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  123. }
  124. }
  125. //获得底部导航
  126. const bottomMenu = ref([]);
  127. const getBottomMenu = async () => {
  128. const response = await axios.get(`/web/getWebsiteFooterCategory`);
  129. bottomMenu.value = response.data;
  130. }
  131. onMounted(() => {
  132. //获得详情
  133. getNewsInfo()
  134. // 获得左侧导航
  135. getBottomMenu()
  136. })
  137. </script>
  138. <style lang="less" scoped>
  139. //导航条
  140. .breadcrumb {
  141. width: 100%;
  142. height: 22px;
  143. margin-bottom: 30px;
  144. font-family: Microsoft YaHei, Microsoft YaHei;
  145. font-weight: 400;
  146. font-size: 20px;
  147. color: #666666;
  148. line-height: 23px;
  149. text-align: left;
  150. font-style: normal;
  151. text-transform: none;
  152. .el-breadcrumb::v-deep {
  153. display: inline-block;
  154. vertical-align: -4px;
  155. }
  156. /deep/.el-breadcrumb__inner a,
  157. /deep/.el-breadcrumb__inner.is-link {
  158. color: #666666;
  159. font-weight: 400;
  160. text-decoration: none;
  161. transition: var(--el-transition-color);
  162. }
  163. span {
  164. font-family: Microsoft YaHei, Microsoft YaHei;
  165. font-weight: 400;
  166. font-size: 20px;
  167. color: #666666;
  168. line-height: 23px;
  169. text-align: left;
  170. font-style: normal;
  171. text-transform: none;
  172. }
  173. span:hover {
  174. color: #666666;
  175. }
  176. .location {
  177. margin-right: 20px;
  178. width: 100px;
  179. height: 22px;
  180. font-family: Microsoft YaHei, Microsoft YaHei;
  181. font-weight: 400;
  182. font-size: 20px;
  183. color: #666666;
  184. line-height: 23px;
  185. text-align: left;
  186. font-style: normal;
  187. text-transform: none;
  188. }
  189. }
  190. // 资讯列表
  191. .newsDetail {
  192. width: 100%;
  193. //height: 1400px;
  194. margin-bottom: 70px;
  195. .inner {
  196. width: 1200px;
  197. //height: 1400px;
  198. font-size: 16px;
  199. .innerLeft {
  200. //height: 1400px;
  201. float: right;
  202. .LeftTop {
  203. //height: 522px;
  204. margin-top: 50px;
  205. >h1 {
  206. line-height: 40px;
  207. margin-bottom: 30px;
  208. font-family: Microsoft YaHei, Microsoft YaHei;
  209. font-weight: bold;
  210. font-size: 30px;
  211. color: #333333;
  212. }
  213. >p {
  214. height: 18px;
  215. line-height: 18px;
  216. font-family: Microsoft YaHei, Microsoft YaHei;
  217. font-weight: 400;
  218. font-size: 14px;
  219. color: #999999;
  220. span {
  221. margin-right: 40px;
  222. }
  223. }
  224. >img {
  225. width: 680px;
  226. height: 382px;
  227. padding: 50px 0px 60px 55px;
  228. }
  229. }
  230. .leftBottomTitle {
  231. color: #028E21;
  232. font-size: 24px;
  233. font-weight: bold;
  234. height: 60px;
  235. line-height: 60px;
  236. }
  237. .leftBottom {
  238. width: 790px;
  239. font-size: 20px;
  240. border-top: 1px solid #139602;
  241. padding-top: 40px;
  242. >h3,
  243. >p {
  244. text-indent: 2em;
  245. width: 790px;
  246. font-family: Microsoft YaHei, Microsoft YaHei;
  247. font-size: 20px;
  248. color: #333333;
  249. line-height: 23px;
  250. padding-bottom: 30px;
  251. }
  252. >h3 {
  253. font-weight: 600px;
  254. }
  255. >p {
  256. font-weight: 400;
  257. }
  258. }
  259. }
  260. .innerRight {
  261. width: 279px;
  262. .rightMenuTitle {
  263. width: 279px;
  264. height: 69px;
  265. font-size: 22px;
  266. font-weight: bold;
  267. line-height: 58px;
  268. text-align: center;
  269. color: #fff;
  270. background: url("../../static/special/projectMoreTitle.png") no-repeat;
  271. margin-bottom: 30px;
  272. }
  273. ul {
  274. li {
  275. a {
  276. border-left: 5px solid #028E21;
  277. margin-bottom: 15px;
  278. font-size: 22px;
  279. display: block;
  280. height: 61px;
  281. line-height: 61px;
  282. color: #333333;
  283. text-align: center;
  284. background: #FBFBFB;
  285. }
  286. }
  287. }
  288. .active {
  289. border-left: 0;
  290. border: 1px solid #028E21;
  291. background: #fff;
  292. }
  293. }
  294. }
  295. }
  296. </style>